<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        body {
            background-color: slategrey;
        }

        span {
            color: yellow;
            font-size: 30px;
        }
    </style>
</head>

<body>
    <span class="fa fa-star-o"></span>
    <span class="fa fa-star-o"></span>
    <span class="fa fa-star-o"></span>
    <span class="fa fa-star-o"></span>
    <span class="fa fa-star-o"></span>
    <script src="../jquery-1.12.4.js"></script>
    <script>
        let $span = $("span");
        let index = 0;
        $span.click(function () {
            // 排他思想让全部变空星星再渲染
            $(this).siblings().removeClass("fa-star");
            $(this).siblings().addClass("fa-star-o");
            index = $(this).index();
            $span.each(function () {
                if ($(this).index() <= index) {
                    // 根据信号量下标,来判断点亮星星数量
                    $(this).removeClass("fa-star-o");
                    $(this).addClass("fa-star");
                }

            })
        });

    </script>
</body>

</html>